package com.routon.plcloud.device.api.controller.personal.vrclient;

import com.alibaba.fastjson.JSONObject;
import com.routon.plcloud.device.core.service.FileinfoService;
import com.routon.plcloud.device.data.entity.Fileinfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author FireWang
 * @date 2021/9/6 17:00
 * 该类用于管理虚拟EMQ客户端设备
 */
@Controller
@RequestMapping(value = "/personal")
public class PersonalController {
    private static Logger logger = LoggerFactory.getLogger(PersonalController.class);

    @Autowired
    private FileinfoService fileinfoService;

    /**
     * 主页进入页面
     *
     * @return
     */
    @RequestMapping(value = "/start")
    public String start() throws Exception {
        return "personal/start";
    }

    /**
     * 验证生日
     *
     * @param request
     * @param passport
     * @return
     */
    @RequestMapping(value = "/goPass")
    @ResponseBody
    public JSONObject goPass(HttpServletRequest request, String passport) {
        HttpSession session = request.getSession();
        JSONObject resJson = new JSONObject();
        String msg = "success";
        try {
            String pass = "11月29日";
            String wrongPass[] ={"8月2日", "8月30日", "9月8日"};
            if (passport.equals("8月2日") || passport.equals("9月8日")) {
                msg = "是让你输我的生日，不是你的！看你还记不记得";
            } else if (!passport.equals("11月29日") && !passport.equals("11月29") && !passport.equals("1129")) {
                msg = "你是不是把我生日忘了，再给你一次机会！";
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
            msg = "进入失败：系统异常！";
        }
        resJson.put("obj1", msg);
        return resJson;
    }

    /**
     * 主页进入页面
     *
     * @return
     */
    @RequestMapping(value = "/page")
    public String page() {
        return "personal/page";
    }


    /**
     * 执行登出
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/passout")
    public String logout(HttpServletRequest request) {
        return "personal/start";
    }

    /**
     * 获取文件列表
     *
     * @return
     */
    @RequestMapping(value = "/getFileList")
    @ResponseBody
    public JSONObject getFileList(HttpServletRequest request) {
        JSONObject jsonMsg = new JSONObject();
        String msg = "success";
        try {
            /* 获取文件列表 */
            List<Fileinfo> walllist = fileinfoService.getFileList(1);
            List<Fileinfo> videolist = fileinfoService.getFileList(2);
            List<Fileinfo> pagelist = fileinfoService.getFileList(3);
            List<Fileinfo> musiclist = fileinfoService.getFileList(4);
            jsonMsg.put("walllist", walllist);
            jsonMsg.put("videolist", videolist);
            jsonMsg.put("pagelist", pagelist);
            jsonMsg.put("musiclist", musiclist);
        } catch (Exception e) {
            e.printStackTrace();
            msg = "系统异常！";
        }
        jsonMsg.put("obj1", msg);
        return jsonMsg;
    }

    /**
     * 添加爱心
     *
     * @return
     */
    @RequestMapping(value = "/addLove")
    @ResponseBody
    public JSONObject addLove(HttpServletRequest request, int id) {
        JSONObject jsonMsg = new JSONObject();
        String msg = "success";
        try {
            int count = fileinfoService.addLove(id);
            jsonMsg.put("count", count);
        } catch (Exception e) {
            e.printStackTrace();
            msg = "系统异常！";
        }
        jsonMsg.put("obj1", msg);
        return jsonMsg;
    }
}
